package com.yl.googleplayer_yl.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yl.googleplayer_yl.holder.BaseHolder;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/1 0001.
 */
public abstract class BasicAdapter<T> extends BaseAdapter {
    public BasicAdapter(ArrayList<T> appInfos) {
        this.list = appInfos;
    }

    private ArrayList<T> list;


    @Override

    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //AppInfo appInfo = (AppInfo) list.get(position);
        BaseHolder<T> baseHolder =null;
        if (convertView == null) {
            baseHolder =getHolder();
        } else {
            baseHolder = (BaseHolder) convertView.getTag();
        }

        baseHolder.bindData(list.get(position));
        return baseHolder.getView();
    }

    protected abstract BaseHolder getHolder();


}